package com.weddingee.util;


public class DatabaseConnectionManager {
	 /*private static ComboPooledDataSource cpds = null; 

	public static void init() { 
	       // 建立数据库连接池 
	        String DRIVER_NAME = SystemConfig.getConfigInfomation("DRIVER_NAME"); // 驱动器 
	        String DATABASE_URL = SystemConfig.getConfigInfomation("DATABASE_URL"); // 数据库连接url 
	        String DATABASE_USER = SystemConfig.getConfigInfomation("DATABASE_USER"); // 数据库用户名 
	        String DATABASE_PASSWORD = SystemConfig.getConfigInfomation("DATABASE_PASSWORD"); // 数据库密码 
	       int Min_PoolSize = 5; 
	       int Max_PoolSize = 50; 
	       int Acquire_Increment = 5; 
	       int Initial_PoolSize = 10; 
	       // 每隔3000s测试连接是否可以正常使用 
	       int Idle_Test_Period = 3000; 
	       // 每次连接验证连接是否可用 
	        String Validate = SystemConfig.getConfigInfomation("Validate"); 
	   if (Validate.equals("")) { 
	           Validate = "false"; 
	       } 
	       // 最小连接数 
	        try { 
	            Min_PoolSize = Integer.parseInt(SystemConfig.getConfigInfomation("Min_PoolSize")); 
	       } catch (Exception ex) { 
	           ex.printStackTrace(); 
	       } 
	       // 增量条数 
	        try { 
	            Acquire_Increment = Integer.parseInt(SystemConfig.getConfigInfomation("Acquire_Increment")); 
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	        } 
	        // 最大连接数 
	        try { 
	            Max_PoolSize = Integer.parseInt(SystemConfig.getConfigInfomation("Max_PoolSize")); 
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	        } 
	        // 初始化连接数 
	        try { 
	            Initial_PoolSize = Integer.parseInt(SystemConfig.getConfigInfomation("Initial_PoolSize")); 
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	        } 
	        // 每隔3000s测试连接是否可以正常使用 
	        try { 
	            Idle_Test_Period = Integer.parseInt(SystemConfig.getConfigInfomation("Idle_Test_Period")); 
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	        } 

	        try { 
	              cpds = new ComboPooledDataSource(); 
	              cpds.setDriverClass(DRIVER_NAME); // 驱动器 
	              cpds.setJdbcUrl(DATABASE_URL); // 数据库url 
	              cpds.setUser(DATABASE_USER); // 用户名 
	              cpds.setPassword(DATABASE_PASSWORD); // 密码 
	              cpds.setInitialPoolSize(Initial_PoolSize); // 初始化连接池大小 
	              cpds.setMinPoolSize(Min_PoolSize); // 最少连接数 
	              cpds.setMaxPoolSize(Max_PoolSize); // 最大连接数 
	              cpds.setAcquireIncrement(Acquire_Increment); // 连接数的增量 
	              cpds.setIdleConnectionTestPeriod(Idle_Test_Period); // 测连接有效的时间间隔 
	              cpds.setTestConnectionOnCheckout(Boolean.getBoolean(Validate)); // 每次连接验证连接是否可用
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	       } 
	    } 

	    public static Connection getConnection() { 
	            Connection connection = null; 
	        try { 
	            if (cpds == null) { 
	                init(); 
	            } 
	            // getconnection 
	            connection = cpds.getConnection(); 
	        } catch (SQLException ex) { 
	            ex.printStackTrace(); 
	        } 
	        return connection; 
	    } 

	    public static void release() { 
	        try { 
	            if (cpds != null) { 
	                cpds.close(); 
	            } 
	        } catch (Exception ex) { 
	            ex.printStackTrace(); 
	        } 
	    } 
	    
	    public static void main(String[] args) {
	    	DatabaseConnectionManager.init();
	    	Connection conn = DatabaseConnectionManager.getConnection();
	    	System.out.println("jjj");
	    	System.out.println(conn);
	    	Statement stm = null;
			try {
				stm = conn.createStatement();
				int res = stm.executeUpdate("insert into news values(null,'daniel1','2012-06-07','hello,world1!','/test/test1.jpg')");
				
				System.out.println(res);
			} catch (SQLException e) {
				e.printStackTrace();
			} finally{
				try {
					stm.close();
					conn.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
	    	
	    	try {
	    		stm = conn.createStatement();
				ResultSet rs = stm.executeQuery("select * from news");
				while( rs.next()){
					String name = rs.getString("name");
					System.out.println(name);
				}
			} catch (SQLException e) {
				try {
					stm.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
			
			try {
	    		stm = conn.createStatement();
				ResultSet rs = stm.executeQuery("select * from news");
				while( rs.next()){
					String name = rs.getString("ID");
					System.out.println(name);
				}
			} catch (SQLException e) {
				try {
					stm.close();
					conn.close();
				} catch (SQLException e1) {
					e1.printStackTrace();
				}
			}
		}*/
}
